Skip to content

Commit 489ce2a

Browse files
committed
social logins and register page implemented.
1 parent bfc5e3f commit 489ce2a

File tree

12 files changed

+63
-176
lines changed

12 files changed

+63
-176
lines changed

src/AbpCompanyName.AbpProjectName.Web/Controllers/AccountController.cs

Lines changed: 3 additions & 150 deletions
Original file line numberDiff line numberDiff line change
@@ -150,18 +150,9 @@ private ActionResult RegisterView(RegisterViewModel model)
150150
[UnitOfWork]
151151
public virtual async Task<ActionResult> Register(RegisterViewModel model)
152152
{
153-
#region MyRegion
154-
155-
/*
156-
try
153+
try
157154
{
158-
CheckSelfRegistrationIsEnabled();
159-
160-
if (!model.IsExternalLogin && UseCaptchaOnRegistration())
161-
{
162-
await CheckCaptchaResponseAsync(_recaptchaValidationService);
163-
}
164-
155+
//Get tenancy name and tenant
165156
if (!_multiTenancyConfig.IsEnabled)
166157
{
167158
model.TenancyName = Tenant.DefaultTenantName;
@@ -177,140 +168,6 @@ public virtual async Task<ActionResult> Register(RegisterViewModel model)
177168

178169
CurrentUnitOfWork.SetTenantId(tenant.Id);
179170

180-
if (!await SettingManager.GetSettingValueForTenantAsync<bool>(AppSettings.UserManagement.AllowSelfRegistration, tenant.Id))
181-
{
182-
throw new UserFriendlyException(L("SelfUserRegistrationIsDisabledMessage_Detail"));
183-
}
184-
185-
//Getting tenant-specific settings
186-
var isNewRegisteredUserActiveByDefault = await SettingManager.GetSettingValueForTenantAsync<bool>(AppSettings.UserManagement.IsNewRegisteredUserActiveByDefault, tenant.Id);
187-
var isEmailConfirmationRequiredForLogin = await SettingManager.GetSettingValueForTenantAsync<bool>(AbpZeroSettingNames.UserManagement.IsEmailConfirmationRequiredForLogin, tenant.Id);
188-
189-
var user = new User
190-
{
191-
TenantId = tenant.Id,
192-
Name = model.Name,
193-
Surname = model.Surname,
194-
EmailAddress = model.EmailAddress,
195-
IsActive = isNewRegisteredUserActiveByDefault
196-
};
197-
198-
ExternalLoginUserInfo externalLoginInfo = null;
199-
if (model.IsExternalLogin)
200-
{
201-
externalLoginInfo = await HttpContext.Authentication.GetExternalLoginUserInfo(model.ExternalLoginAuthSchema);
202-
if (externalLoginInfo == null)
203-
{
204-
throw new ApplicationException("Can not external login!");
205-
}
206-
207-
user.Logins = new List<UserLogin>
208-
{
209-
new UserLogin
210-
{
211-
LoginProvider = externalLoginInfo.LoginInfo.LoginProvider,
212-
ProviderKey = externalLoginInfo.LoginInfo.ProviderKey,
213-
TenantId = tenant.Id
214-
}
215-
};
216-
217-
model.UserName = model.EmailAddress;
218-
model.Password = Authorization.Users.User.CreateRandomPassword();
219-
220-
if (string.Equals(externalLoginInfo.EmailAddress, model.EmailAddress, StringComparison.InvariantCultureIgnoreCase))
221-
{
222-
user.IsEmailConfirmed = true;
223-
}
224-
}
225-
else
226-
{
227-
if (model.UserName.IsNullOrEmpty() || model.Password.IsNullOrEmpty())
228-
{
229-
throw new UserFriendlyException(L("FormIsNotValidMessage"));
230-
}
231-
}
232-
233-
user.UserName = model.UserName;
234-
user.Password = new PasswordHasher().HashPassword(model.Password);
235-
236-
user.Roles = new List<UserRole>();
237-
foreach (var defaultRole in await _roleManager.Roles.Where(r => r.IsDefault).ToListAsync())
238-
{
239-
user.Roles.Add(new UserRole(tenant.Id, user.Id, defaultRole.Id));
240-
}
241-
242-
CheckErrors(await _userManager.CreateAsync(user));
243-
await _unitOfWorkManager.Current.SaveChangesAsync();
244-
245-
if (!user.IsEmailConfirmed)
246-
{
247-
user.SetNewEmailConfirmationCode();
248-
await _userEmailer.SendEmailActivationLinkAsync(user);
249-
}
250-
251-
//Notifications
252-
await _notificationSubscriptionManager.SubscribeToAllAvailableNotificationsAsync(user.ToUserIdentifier());
253-
await _appNotifier.WelcomeToTheApplicationAsync(user);
254-
await _appNotifier.NewUserRegisteredAsync(user);
255-
256-
//Directly login if possible
257-
if (user.IsActive && (user.IsEmailConfirmed || !isEmailConfirmationRequiredForLogin))
258-
{
259-
AbpUserManager<Tenant, Role, User>.AbpLoginResult loginResult;
260-
if (externalLoginInfo != null)
261-
{
262-
loginResult = await _userManager.LoginAsync(externalLoginInfo.LoginInfo, tenant.TenancyName);
263-
}
264-
else
265-
{
266-
loginResult = await GetLoginResultAsync(user.UserName, model.Password, tenant.TenancyName);
267-
}
268-
269-
if (loginResult.Result == AbpLoginResultType.Success)
270-
{
271-
await SignInAsync(loginResult.User, loginResult.Identity);
272-
return Redirect(GetAppHomeUrl());
273-
}
274-
275-
Logger.Warn("New registered user could not be login. This should not be normally. login result: " + loginResult.Result);
276-
}
277-
278-
return View("RegisterResult", new RegisterResultViewModel
279-
{
280-
TenancyName = tenant.TenancyName,
281-
NameAndSurname = user.Name + " " + user.Surname,
282-
UserName = user.UserName,
283-
EmailAddress = user.EmailAddress,
284-
IsActive = user.IsActive,
285-
IsEmailConfirmationRequired = isEmailConfirmationRequiredForLogin
286-
});
287-
}
288-
catch (UserFriendlyException ex)
289-
{
290-
ViewBag.IsMultiTenancyEnabled = _multiTenancyConfig.IsEnabled;
291-
ViewBag.UseCaptcha = !model.IsExternalLogin && UseCaptchaOnRegistration();
292-
ViewBag.ErrorMessage = ex.Message;
293-
294-
return View("Register", model);
295-
}
296-
*/
297-
298-
#endregion
299-
300-
try
301-
{
302-
//Get tenancy name and tenant
303-
if (!_multiTenancyConfig.IsEnabled)
304-
{
305-
model.TenancyName = Tenant.DefaultTenantName;
306-
}
307-
else if (model.TenancyName.IsNullOrEmpty())
308-
{
309-
throw new UserFriendlyException(L("TenantNameCanNotBeEmpty"));
310-
}
311-
312-
var tenant = await GetActiveTenantAsync(model.TenancyName);
313-
314171
//Create user
315172
var user = new User
316173
{
@@ -341,7 +198,7 @@ public virtual async Task<ActionResult> Register(RegisterViewModel model)
341198
}
342199
};
343200

344-
model.UserName = model.EmailAddress;
201+
model.UserName = model.UserName;
345202
model.Password = Users.User.CreateRandomPassword();
346203

347204
if (string.Equals(externalLoginInfo.EmailAddress, model.EmailAddress, StringComparison.InvariantCultureIgnoreCase))
@@ -360,10 +217,6 @@ public virtual async Task<ActionResult> Register(RegisterViewModel model)
360217
user.UserName = model.UserName;
361218
user.Password = new PasswordHasher().HashPassword(model.Password);
362219

363-
//Switch to the tenant
364-
_unitOfWorkManager.Current.EnableFilter(AbpDataFilters.MayHaveTenant); //TODO: Needed?
365-
_unitOfWorkManager.Current.SetTenantId(tenant.Id);
366-
367220
//Add default roles
368221
user.Roles = new List<UserRole>();
369222
foreach (var defaultRole in await _roleManager.Roles.Where(r => r.IsDefault).ToListAsync())

src/AbpCompanyName.AbpProjectName.Web/Models/Account/RegisterViewModel.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11
using System.Collections.Generic;
22
using System.ComponentModel.DataAnnotations;
33
using System.Text.RegularExpressions;
4-
using Abp.Application.Services.Dto;
54
using AbpCompanyName.AbpProjectName.MultiTenancy;
65
using AbpCompanyName.AbpProjectName.Users;
76
using Abp.Extensions;
87

98
namespace AbpCompanyName.AbpProjectName.Web.Models.Account
109
{
11-
public class RegisterViewModel : IInputDto, IValidatableObject
10+
public class RegisterViewModel : IValidatableObject
1211
{
1312
/// <summary>
1413
/// Not required for single-tenant applications.

src/AbpCompanyName.AbpProjectName.Web/Views/Account/Login.cshtml

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -81,9 +81,9 @@
8181
{
8282
provider = provider.ToLower(CultureInfo.InvariantCulture);
8383

84-
if (provider == "google")
84+
if (provider == "microsoft")
8585
{
86-
return "googleplus";
86+
return "windows";
8787
}
8888

8989
return provider;
@@ -100,13 +100,11 @@
100100
<input type="hidden" name="provider" value="" />
101101

102102
@foreach (var p in loginProviders)
103-
{
104-
<li>
105-
<a class="social-login-icon social-icon-color @getSocialIconClass(p.DisplayName)"
106-
title="@p.DisplayName"
107-
data-provider="@p.DisplayName"
108-
href="javascript:;"></a>
109-
</li>
103+
{
104+
<a class="btn btn-default btn-sm fa fa-@(getSocialIconClass(p.DisplayName)) social-login-link" title="@p.DisplayName"
105+
data-provider="@p.DisplayName"
106+
href="javascript:;">
107+
</a>
110108
}
111109
</form>
112110
</ul>

src/AbpCompanyName.AbpProjectName.Web/Views/Account/Register.cshtml

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,31 @@
1-
@model AbpCompanyName.AbpProjectName.WebMpa.Models.Account.RegisterViewModel
1+
@model AbpCompanyName.AbpProjectName.Web.Models.Account.RegisterViewModel
2+
@{
3+
ViewBag.DisableTopBar = true;
4+
}
25
@section Styles
36
{
4-
<link href="~/Views/Account/Login.css" rel="stylesheet" />
7+
<environment names="Development">
8+
<link rel="stylesheet" href="~/view-resources/Views/Account/Login.css" asp-append-version="true" />
9+
</environment>
10+
11+
<environment names="Staging,Production">
12+
<link rel="stylesheet" href="~/view-resources/Views/Account/Login.min.css" asp-append-version="true" />
13+
</environment>
514
}
615
@section Scripts{
7-
<script type="text/javascript" src="~/Views/Account/Register.js"></script>
16+
<environment names="Development">
17+
<script src="~/view-resources/Views/Account/Register.js" asp-append-version="true"></script>
18+
</environment>
19+
20+
<environment names="Staging,Production">
21+
<script src="~/view-resources/Views/Account/Register.min.js" asp-append-version="true"></script>
22+
</environment>
823
}
924
<div class="container">
1025
<div id="LoginArea" class="row">
1126
<div class="col-lg-12">
1227
<div class="well bs-component">
13-
<form class="form-horizontal register-form" action="@(Url.Action("Register","Account"))" method="POST">
28+
<form asp-action="Register" class="form-horizontal register-form" method="POST">
1429
<fieldset>
1530
<legend>@L("Register")</legend>
1631

@@ -31,6 +46,7 @@
3146
}
3247

3348
<input type="hidden" name="IsExternalLogin" value="@Model.IsExternalLogin.ToString()" />
49+
<input type="hidden" name="ExternalLoginAuthSchema" value="@Model.ExternalLoginAuthSchema"/>
3450

3551
<div class="form-group">
3652
<div class="col-lg-12">

src/AbpCompanyName.AbpProjectName.Web/Views/Account/RegisterResult.cshtml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
@model AbpCompanyName.AbpProjectName.WebMpa.Models.Account.RegisterResultViewModel
1+
@model AbpCompanyName.AbpProjectName.Web.Models.Account.RegisterResultViewModel
22
@{
33
ViewBag.Title = "Successfully registered";
44
}

src/AbpCompanyName.AbpProjectName.Web/Views/Account/TenantSelection.cshtml

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,16 @@
1-
@model AbpCompanyName.AbpProjectName.WebMpa.Models.Account.TenantSelectionViewModel
1+
@model AbpCompanyName.AbpProjectName.Web.Models.Account.TenantSelectionViewModel
22
@{
33
ViewBag.Title = "Select Tenant";
44
}
55
@section Styles
66
{
7-
<link href="~/Views/Account/Login.css" rel="stylesheet" />
7+
<environment names="Development">
8+
<link rel="stylesheet" href="~/view-resources/Views/Account/Login.css" asp-append-version="true" />
9+
</environment>
10+
11+
<environment names="Staging,Production">
12+
<link rel="stylesheet" href="~/view-resources/Views/Account/Login.min.css" asp-append-version="true" />
13+
</environment>
814
}
915
<div class="container">
1016
<div id="LoginArea" class="row">
@@ -26,18 +32,18 @@
2632
var tenant = Model.Tenants[i];
2733
<div class="md-radio">
2834
@{
29-
string checkAttr = null;
30-
if (i == 0)
31-
{
32-
checkAttr = "checked=\"checked\"";
33-
}
35+
string checkAttr = null;
36+
if (i == 0)
37+
{
38+
checkAttr = "checked=\"checked\"";
39+
}
3440
}
3541
<input type="radio" class="md-radiobtn" id="TenancyName_@(tenant.TenancyName)" name="TenancyName" value="@tenant.TenancyName" @checkAttr>
3642
<label for="TenancyName_@(tenant.TenancyName)">
3743
@tenant.Name (@tenant.TenancyName)
3844
</label>
3945
</div>
40-
}
46+
}
4147
</div>
4248
</div>
4349

src/AbpCompanyName.AbpProjectName.Web/Views/Shared/_Layout.cshtml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,10 @@
4141

4242
</head>
4343
<body>
44-
@Html.Partial("_TopBar")
44+
@if (ViewBag.DisableTopBar == null || ViewBag.DisableTopBar != true)
45+
{
46+
Html.RenderPartial("_TopBar");
47+
}
4548

4649
<div class="container">
4750
@RenderBody()

src/AbpCompanyName.AbpProjectName.Web/compilerconfig.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,9 @@
66
{
77
"outputFile": "wwwroot/view-resources/Views/Account/Login.es5.js",
88
"inputFile": "wwwroot/view-resources/Views/Account/Login.js"
9+
},
10+
{
11+
"outputFile": "wwwroot/view-resources/Views/Account/Login.css",
12+
"inputFile": "wwwroot/view-resources/Views/Account/Login.less"
913
}
1014
]

src/AbpCompanyName.AbpProjectName.Web/project.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
},
4242

4343
"tools": {
44+
"Microsoft.Extensions.SecretManager.Tools": "1.0.0-preview2-final",
4445
"Microsoft.AspNetCore.Razor.Tools": "1.0.0-preview2-final",
4546
"Microsoft.AspNetCore.Server.IISIntegration.Tools": "1.0.0-preview2-final",
4647
"Microsoft.EntityFrameworkCore.Tools": "1.0.0-preview2-final",

src/AbpCompanyName.AbpProjectName.Web/wwwroot/view-resources/Views/Account/Login.css

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,6 @@
22
max-width: 400px;
33
margin: 120px auto 10px auto;
44
}
5+
.social-icons {
6+
padding-left: 0px;
7+
}

0 commit comments

Comments
 (0)