Login.cshtml 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  1. @using WeApp
  2. @using WeApp.Configuration
  3. @using WeApp.Views.Shared.Modals
  4. @model WeApp.Models.Account.LoginFormViewModel
  5. @{
  6. ViewBag.Title = L("LogIn");
  7. }
  8. @section styles
  9. {
  10. }
  11. @section scripts
  12. {
  13. <script>
  14. (function () {
  15. $(function () {
  16. var $loginForm = $('#LoginForm');
  17. $loginForm.submit(function (e) {
  18. e.preventDefault();
  19. if (!$loginForm.valid()) {
  20. return;
  21. }
  22. abp.ui.setBusy(
  23. $('#LoginArea'),
  24. $.iwbAjax4({
  25. url: '/Account/Login',
  26. form: $loginForm,
  27. success: function () {
  28. abp.ui.setBusy();
  29. abp.message.success("登陆成功", "登陆");
  30. },
  31. error: function (error) {
  32. if (error.details) {
  33. return abp.message.error(error.details, error.message);
  34. } else {
  35. return abp.message.error(error.message || abp.ajax.defaultError.message);
  36. }
  37. }
  38. })
  39. );
  40. });
  41. $('a.social-login-link').click(function () {
  42. var $a = $(this);
  43. var $form = $a.closest('form');
  44. $form.find('input[name=provider]').val($a.attr('data-provider'));
  45. $form.submit();
  46. });
  47. $('input[name=returnUrlHash]').val(location.hash);
  48. $('#LoginForm input:first-child').focus();
  49. });
  50. })();
  51. function RememberChange(that) {
  52. var $that = $(that);
  53. $that.val($that.is(':checked'));
  54. }
  55. </script>
  56. @if (ViewBag.IsMultiTenancyEnabled)
  57. {
  58. <script>
  59. function changeTenant() {
  60. $('#TenantChangeModal').iwbModal();
  61. }
  62. (function () {
  63. $(function() {
  64. var $tenantChangeForm = $('#TenantChangeForm');
  65. $tenantChangeForm.find('select').select2();
  66. function switchToSelectedTenant() {
  67. var tenancyName = $tenantChangeForm.find('#TenancyName').val();
  68. if (!tenancyName) {
  69. abp.multiTenancy.setTenantIdCookie(null);
  70. location.reload();
  71. return;
  72. }
  73. $.iwbAjax4({
  74. url: '@Path.Combine(ApplicationPath, IwbConsts.ApiAppUrl)account/isTenantAvailable',
  75. form:$tenantChangeForm,
  76. success: function (result) {
  77. switch (result.state) {
  78. case 1: //Available
  79. abp.multiTenancy.setTenantIdCookie(result.tenantId);
  80. //_modalManager.close();
  81. location.reload();
  82. return;
  83. case 2: //InActive
  84. abp.message.warn(abp.utils.formatString(abp.localization
  85. .localize("TenantIsNotActive", "WeApp"),
  86. tenancyName));
  87. break;
  88. case 3: //NotFound
  89. abp.message.warn(abp.utils.formatString(abp.localization
  90. .localize("ThereIsNoTenantDefinedWithName{0}", "WeApp"),
  91. tenancyName));
  92. break;
  93. }
  94. }
  95. });
  96. }
  97. //Handle save button click
  98. $tenantChangeForm.closest('div.modal-content').find(".save-btn").click(function (e) {
  99. e.preventDefault();
  100. switchToSelectedTenant();
  101. });
  102. //Handle enter key
  103. $tenantChangeForm.find('input').on('keypress', function (e) {
  104. if (e.which === 13) {
  105. e.preventDefault();
  106. switchToSelectedTenant();
  107. }
  108. });
  109. //$.AdminBSB.input.activate($tenantChangeForm);
  110. //$('#TenantChangeModal').on('shown.bs.modal', function () {
  111. // $tenantChangeForm.find('input[type=text]:first').focus();
  112. //});
  113. });
  114. })();
  115. </script>
  116. }
  117. }
  118. <div class="card">
  119. <div class="body">
  120. @if (ViewBag.IsMultiTenancyEnabled)
  121. {
  122. <div class="text-center" style="margin-bottom: 3px;">
  123. <span>
  124. @L("CurrentTenant"):
  125. @if (Model.Tenant != null)
  126. {
  127. <span title="@Model.Tenant.Name"><strong>@Model.Tenant.TenancyName</strong></span>
  128. }
  129. else
  130. {
  131. <span>@L("NotSelected")</span>
  132. }
  133. (<a href="javascript:void(0)" data-toggle="modal" onclick="changeTenant()">@L("Change")</a>)
  134. </span>
  135. </div>
  136. List<SelectListItem> tenantList = ViewBag.TenantList;
  137. var tenantModal = new ModalViewModel(L("ChangeTenant"), "", new ModalBodyViewModel(new List<Input>()
  138. {
  139. new Input("TenancyName", L("TenancyName")).SetSelectOptions(tenantList,isAddBlank:false)
  140. //.SetHelp(L("LeaveEmptyToSwitchToHost"))
  141. }, "TenantChangeForm"), "TenantChangeModal");
  142. @section modal{
  143. @Html.Partial("Modals/_Modal", tenantModal)
  144. }
  145. }
  146. <form id="LoginForm" method="POST">
  147. <input type="hidden" name="returnUrl" value="@Model.ReturnUrl" />
  148. <input type="hidden" name="returnUrlHash" />
  149. <h4 class="text-center login-title">@L("LogIn")</h4>
  150. <div class="input-group">
  151. <span class="input-group-prepend">
  152. <span class="input-group-text"><i class="fa fa-user"></i></span>
  153. </span>
  154. <input type="text" class="form-control" name="UsernameOrEmailAddress" required autofocus maxlength="100">
  155. </div>
  156. <div class="input-group">
  157. <span class="input-group-prepend">
  158. <span class="input-group-text"><i class="fa fa-lock"></i></span>
  159. </span>
  160. <input type="password" class="form-control" name="Password" required maxlength="100">
  161. </div>
  162. <div class="row">
  163. <div class="col-9">
  164. @*<input type="checkbox" name="RememberMe" id="rememberme" class="filled-in chk-col-pink" value="true">
  165. <label for="rememberme">@L("RememberMe")</label>*@
  166. <label class="iwb-checkbox">
  167. <input data-index="0" name="rememberMe" id="rememberme" type="checkbox" value="false" onchange="RememberChange(this)">
  168. <span></span>
  169. @L("RememberMe")
  170. </label>
  171. </div>
  172. <div class="col-3">
  173. <button id="LoginButton" class="btn btn-sm btn-block btn-iwb waves-effect" type="submit">@L("LogIn")</button>
  174. </div>
  175. </div>
  176. @if (Model.IsSelfRegistrationAllowed)
  177. {
  178. <div class="row">
  179. <div class="col-12">
  180. <a href="@Url.Action("Register", "Account")">@L("Register")</a>
  181. </div>
  182. </div>
  183. }
  184. </form>
  185. </div>
  186. </div>