Skip to content

Commit ff7db5f

Browse files
committed
1. Showing Initials if the profile pic not uploaded
2. UI Fixes 3. Sharing options 4. Third-party login
1 parent 1048c10 commit ff7db5f

27 files changed

+205
-81
lines changed

src/LetsDisc.Application/LetsDisc.Application.csproj

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,9 @@
1414
<DefineConstants>FEATURE_SIGNALR_ASPNETCORE</DefineConstants>
1515
</PropertyGroup>
1616
<ItemGroup>
17-
<ProjectReference Include="..\LetsDisc.Core\LetsDisc.Core.csproj" />
17+
<PackageReference Include="Microsoft.AspNetCore.Mvc" Version="2.2.0" />
1818
</ItemGroup>
1919
<ItemGroup>
20-
<Reference Include="Microsoft.AspNetCore.Mvc.Core">
21-
<HintPath>C:\Program Files\dotnet\sdk\NuGetFallbackFolder\microsoft.aspnetcore.mvc.core\2.1.1\lib\netstandard2.0\Microsoft.AspNetCore.Mvc.Core.dll</HintPath>
22-
</Reference>
20+
<ProjectReference Include="..\LetsDisc.Core\LetsDisc.Core.csproj" />
2321
</ItemGroup>
2422
</Project>

src/LetsDisc.Application/Posts/PostAppService.cs

Lines changed: 35 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
using Abp.AutoMapper;
44
using Abp.Domain.Entities;
55
using Abp.Domain.Repositories;
6+
using LetsDisc.Authorization.Users;
67
using LetsDisc.PostDetails;
78
using LetsDisc.Posts.Dto;
89
using LetsDisc.Tags;
@@ -36,16 +37,19 @@ public class PostAppService : AsyncCrudAppService<Post, PostDto, int, PagedAndSo
3637
private readonly IRepository<Vote> _voteRepository;
3738
private readonly IRepository<Tag> _tagRepository;
3839
private readonly IRepository<PostTag> _postTagRepository;
40+
private readonly IRepository<UserDetails, long> _userDetailsRepository;
3941

4042
public PostAppService(IRepository<Post> postRepository,
4143
IRepository<Vote> voteRepository,
4244
IRepository<Tag> tagRepository,
43-
IRepository<PostTag> postTagRepository) : base(postRepository)
45+
IRepository<PostTag> postTagRepository,
46+
IRepository<UserDetails, long> userDetailsRepository) : base(postRepository)
4447
{
4548
_postRepository = postRepository;
4649
_voteRepository = voteRepository;
4750
_tagRepository = tagRepository;
4851
_postTagRepository = postTagRepository;
52+
_userDetailsRepository = userDetailsRepository;
4953
}
5054

5155
public override async Task<PostDto> Create(CreatePostDto input)
@@ -287,69 +291,87 @@ public async Task<PagedResultDto<PostDto>> GetSearchPosts(PagedAndSortedResultRe
287291
};
288292
}
289293

294+
private static VoteChangeOutput ReturnVoteChangeOutput(Post post, bool upvote, bool downvote)
295+
{
296+
return new VoteChangeOutput()
297+
{
298+
VoteCount = post.Score,
299+
UpVote = upvote,
300+
DownVote = downvote,
301+
PostTypeId = post.PostTypeId,
302+
PostId = post.Id
303+
};
304+
}
305+
306+
private void decreaseUserReputation(UserDetails user, int dec)
307+
{
308+
user.Reputation -= dec;
309+
}
310+
311+
private void increaseUserReputation(UserDetails user, int inc)
312+
{
313+
user.Reputation += inc;
314+
}
315+
290316
//Voting Up the Post both Question and Answer, where there will be two things either Upvoting or Downvoting
291317
public async Task<VoteChangeOutput> PostVoteUp(int id)
292318
{
293319
var post = await _postRepository.GetAsync(id);
294320
var isUserVoted = _voteRepository.FirstOrDefault(userVote => userVote.CreatorUserId == AbpSession.UserId && userVote.PostId == id);
321+
var user = _userDetailsRepository.FirstOrDefault(u => u.UserId == post.CreatorUserId);
295322
if (isUserVoted != null)
296323
{
297324
if(isUserVoted.VoteTypeId == (int)VoteTypes.Upvote)
298325
{
299326
post.Score--;
300327
await _voteRepository.DeleteAsync(isUserVoted.Id);
328+
decreaseUserReputation(user, 10);
301329
}
302330
else if( isUserVoted.VoteTypeId == (int)VoteTypes.Downvote)
303331
{
304332
post.Score += 2;
305333
isUserVoted.VoteTypeId = (int)VoteTypes.Upvote;
334+
increaseUserReputation(user, 12);
306335
return ReturnVoteChangeOutput(post, true, false);
307336
}
308337
}
309338
else
310339
{
311340
post.Score++;
312341
await _voteRepository.InsertAsync(new Vote(id, (int)VoteTypes.Upvote));
342+
increaseUserReputation(user, 10);
313343
return ReturnVoteChangeOutput(post, true, false);
314344
}
315345
return ReturnVoteChangeOutput(post, false, false);
316346
}
317347

318-
private static VoteChangeOutput ReturnVoteChangeOutput(Post post, bool upvote, bool downvote)
319-
{
320-
return new VoteChangeOutput()
321-
{
322-
VoteCount = post.Score,
323-
UpVote = upvote,
324-
DownVote = downvote,
325-
PostTypeId = post.PostTypeId,
326-
PostId = post.Id
327-
};
328-
}
329-
330348
//Voting Down the Post both Question and Answer, where there will be two things either Upvoting or Downvoting
331349
public async Task<VoteChangeOutput> PostVoteDown(int id)
332350
{
333351
var post = await _postRepository.GetAsync(id);
334352
var isUserVoted = _voteRepository.FirstOrDefault(userVote => userVote.CreatorUserId == AbpSession.UserId && userVote.PostId == id);
353+
var user = _userDetailsRepository.FirstOrDefault(u => u.UserId == post.CreatorUserId);
335354
if (isUserVoted != null)
336355
{
337356
if (isUserVoted.VoteTypeId == (int)VoteTypes.Downvote)
338357
{
339358
post.Score++;
340359
await _voteRepository.DeleteAsync(isUserVoted.Id);
360+
increaseUserReputation(user, 2);
341361
}
342362
else if (isUserVoted.VoteTypeId == (int)VoteTypes.Upvote)
343363
{
344364
post.Score -= 2;
345365
isUserVoted.VoteTypeId = (int)VoteTypes.Downvote;
366+
decreaseUserReputation(user, 12);
346367
return ReturnVoteChangeOutput(post, false, true);
347368
}
348369
}
349370
else
350371
{
351372
post.Score--;
352373
await _voteRepository.InsertAsync(new Vote(id, (int)VoteTypes.Downvote));
374+
decreaseUserReputation(user, 2);
353375
return ReturnVoteChangeOutput(post, false, true);
354376
}
355377
return ReturnVoteChangeOutput(post, false, false);

src/LetsDisc.Application/Users/Dto/UserDetailsDto.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ public class UserDetailsDto
1919
public int Downvotes { get; set; }
2020
public string Views { get; set; }
2121
public string ProfileImageUrl { get; set; }
22-
public User User { get; set; }
22+
//public User User { get; set; }
2323
public long UserId { get; set; }
2424
public DateTime CreationTime { get; set; }
2525
}

src/LetsDisc.Core/Authorization/Users/UserRegistrationManager.cs

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -74,18 +74,6 @@ public async Task<User> RegisterAsync(string name, string surname, string emailA
7474
}
7575

7676
CheckErrors(await _userManager.CreateAsync(user));
77-
var emailConfirmationToken = await _userManager.GenerateEmailConfirmationTokenAsync(user);
78-
user.EmailConfirmationCode = emailConfirmationToken;
79-
80-
// The angular app is converting '+' to space, and thus it was giving Invalid Token Problem.
81-
// Encoding it to Base 64 and then decoding while checking the token
82-
byte[] tokenGeneratedBytes = Encoding.UTF8.GetBytes(emailConfirmationToken);
83-
var codeEncoded = WebEncoders.Base64UrlEncode(tokenGeneratedBytes);
84-
85-
var url = String.Format("{0}/account/confirmemail?userId={1}&code={2}", LetsDiscConsts.BaseUrl, user.Id, codeEncoded);
86-
87-
await _emailSender.SendAsync(emailAddress, "Confirm your email",
88-
$"Please confirm your account by <a href='{HtmlEncoder.Default.Encode(url)}'>clicking here</a>.");
8977

9078
await CurrentUnitOfWork.SaveChangesAsync();
9179

src/LetsDisc.Web.Core/Controllers/TokenAuthController.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,10 @@ public List<ExternalLoginProviderInfoModel> GetExternalAuthenticationProviders()
110110
public async Task<ExternalAuthenticateResultModel> ExternalAuthenticate([FromBody] ExternalAuthenticateModel model)
111111
{
112112
var loginResult = await _logInManager.LoginAsync(new UserLoginInfo(model.AuthProvider, model.ProviderKey, model.AuthProvider), GetTenancyNameOrNull());
113-
await _signInManager.SignInAsync(loginResult.Identity, true);
113+
if(loginResult.Identity != null)
114+
{
115+
await _signInManager.SignInAsync(loginResult.Identity, true);
116+
}
114117
await UnitOfWorkManager.Current.SaveChangesAsync();
115118
switch (loginResult.Result)
116119
{

src/LetsDisc.Web.Host/LetsDisc.Web.Host.csproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,11 +88,13 @@
8888
<None Remove="src\app\comma-seperated.pipe.ts" />
8989
<None Remove="src\app\pipes\remove-html-tag.pipe.ts" />
9090
<None Remove="src\app\pipes\truncate-text.pipe.ts" />
91+
<None Remove="src\icons.ts" />
9192
</ItemGroup>
9293
<ItemGroup>
9394
<TypeScriptCompile Include="src\app\account\login.service.ts" />
9495
<TypeScriptCompile Include="src\app\pipes\remove-html-tag.pipe.ts" />
9596
<TypeScriptCompile Include="src\app\pipes\truncate-text.pipe.ts" />
97+
<TypeScriptCompile Include="src\icons.ts" />
9698
</ItemGroup>
9799
<ItemGroup>
98100
<Content Update="appsettings.json">

src/LetsDisc.Web.Host/package.json

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
"private": true,
1515
"dependencies": {
1616
"@angular/animations": "^6.1.10",
17-
"@angular/cdk": "^6.0.5",
17+
"@angular/cdk": "^6.4.7",
1818
"@angular/common": "^6.0.5",
1919
"@angular/compiler": "^6.0.5",
2020
"@angular/core": "^6.0.5",
@@ -29,7 +29,13 @@
2929
"@aspnet/signalr": "^1.0.0",
3030
"@ckeditor/ckeditor5-angular": "^1.1.0",
3131
"@ckeditor/ckeditor5-build-classic": "^12.1.0",
32+
"@fortawesome/angular-fontawesome": "^0.3.0",
33+
"@fortawesome/fontawesome-svg-core": "^1.2.26",
34+
"@fortawesome/free-brands-svg-icons": "^5.12.0",
35+
"@fortawesome/free-solid-svg-icons": "^5.12.0",
3236
"@ng-bootstrap/ng-bootstrap": "^3.3.1",
37+
"@ngx-share/button": "^7.1.4",
38+
"@ngx-share/core": "^7.1.4",
3339
"@types/bootstrap": "^3.3.33",
3440
"@types/jquery": "^3.2.12",
3541
"@types/jquery.blockui": "0.0.28",

src/LetsDisc.Web.Host/src/app/account/account.component.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import { Component, ViewContainerRef, OnInit, ViewEncapsulation, Injector, OnDestroy } from '@angular/core';
2-
//import { LoginService } from './login/login.service';
2+
import { LoginService } from './login.service';
33
import { AppComponentBase } from '@shared/app-component-base';
4-
import { FirebaseUISignInSuccessWithAuthResult, FirebaseUISignInFailure } from 'firebaseui-angular';
54

65
@Component({
76
templateUrl: './account.component.html',
@@ -17,8 +16,8 @@ export class AccountComponent extends AppComponentBase {
1716
currentYear: number;
1817

1918
public constructor(
20-
injector: Injector//,
21-
//private _loginService: LoginService
19+
injector: Injector,
20+
private _loginService: LoginService
2221
) {
2322
super(injector);
2423

@@ -31,6 +30,7 @@ export class AccountComponent extends AppComponentBase {
3130
}
3231

3332
printUser(signInSuccessData) {
33+
this._loginService.externalAuthenticate(signInSuccessData);
3434
console.log(signInSuccessData);
3535
}
3636

src/LetsDisc.Web.Host/src/app/account/login.service.ts

Lines changed: 18 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import { TokenService } from '@abp/auth/token.service';
1111
import { UtilsService } from '@abp/utils/utils.service';
1212
import { finalize } from 'rxjs/operators';
1313
import { Observable, BehaviorSubject } from 'rxjs';
14-
import { GoogleLoginProvider, AuthService } from 'angularx-social-login';
1514

1615
@Injectable()
1716
export class LoginService {
@@ -29,8 +28,7 @@ export class LoginService {
2928
private _utilsService: UtilsService,
3029
private _messageService: MessageService,
3130
private _tokenService: TokenService,
32-
private _logService: LogService,
33-
private authService: AuthService
31+
private _logService: LogService
3432
) {
3533
this.clear();
3634
}
@@ -46,26 +44,24 @@ export class LoginService {
4644
});
4745
}
4846

49-
externalAuthenticate(): void {
50-
this.authService.signIn(GoogleLoginProvider.PROVIDER_ID).then(user => {
51-
const model = new ExternalAuthenticateModel({
52-
authProvider: GoogleLoginProvider.PROVIDER_ID,
53-
providerKey: user.id,
54-
providerAccessCode: user.id,
55-
emailAddress: user.email,
56-
name: user.firstName,
57-
surname: user.lastName
47+
externalAuthenticate(data: any): void {
48+
const model = new ExternalAuthenticateModel({
49+
authProvider: data.o,
50+
providerKey: data.uid,
51+
providerAccessCode: data.uid,
52+
emailAddress: data.email,
53+
name: data.displayName.split(" ")[0],
54+
surname: data.displayName.split(" ")[1]
55+
});
56+
this._tokenAuthService.externalAuthenticate(model)
57+
.subscribe((result: ExternalAuthenticateResultModel) => {
58+
if (result.accessToken) {
59+
this.login(result.accessToken, result.encryptedAccessToken, result.expireInSeconds, false);
60+
} else {
61+
this._logService.warn('Unexpected authenticateResult!');
62+
this._router.navigate(['account/login']);
63+
}
5864
});
59-
this._tokenAuthService.externalAuthenticate(model)
60-
.subscribe((result: ExternalAuthenticateResultModel) => {
61-
if (result.accessToken) {
62-
this.login(result.accessToken, result.encryptedAccessToken, result.expireInSeconds, false);
63-
} else {
64-
this._logService.warn('Unexpected authenticateResult!');
65-
this._router.navigate(['account/login']);
66-
}
67-
})
68-
});
6965
}
7066

7167
private processAuthenticateResult(authenticateResult: AuthenticateResultModel) {

src/LetsDisc.Web.Host/src/app/app.module.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ import { SearchPostsComponent } from './search-posts/search-posts.component';
4444
import { QuillModule } from 'ngx-quill';
4545
import { AccountComponent } from './account/account.component';
4646
import { NgxAuthFirebaseUIModule } from 'ngx-auth-firebaseui';
47+
import { ShareModule } from '@ngx-share/core';
48+
import { FontAwesomeModule } from '@fortawesome/angular-fontawesome';
4749

4850
@NgModule({
4951
declarations: [
@@ -88,7 +90,10 @@ import { NgxAuthFirebaseUIModule } from 'ngx-auth-firebaseui';
8890
TagInputModule,
8991
SocialLoginModule,
9092
QuillModule.forRoot(),
91-
NgxAuthFirebaseUIModule
93+
NgxAuthFirebaseUIModule,
94+
HttpClientModule,
95+
ShareModule,
96+
FontAwesomeModule
9297
],
9398
providers: [
9499
]

0 commit comments

Comments
 (0)