aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/Web/Tango.MachineService/Controllers/FSEAccountController.cs
blob: c8b1628b1c51783d223665c403238c46521a483a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Tango.BL;
using Tango.MachineService.Filters;
using Tango.MachineService.Models;
using Tango.Web.Helpers;
using System.Data.Entity;
using Tango.Web.Storage;
using System.IO;
using Microsoft.WindowsAzure.Storage.Blob;
using System.Net.Http;
using System.Net;
using System.Net.Http.Headers;
using System.Net.Mime;
using Tango.MachineService.Views.FSEAccount;

namespace Tango.MachineService.Controllers
{
    public class FSEAccountController : Controller
    {
        private static Random rnd = new Random();

        public ActionResult ResetPassword(String id)
        {
            ResetPasswordVM vm = new ResetPasswordVM();
            vm.FullName = "Full Name";
            vm.Password = "Password";

            var reset = FSEController.PendingPasswordResets.SingleOrDefault(x => x.ID == id);

            if (reset != null)
            {
                using (ObservablesContext db = ObservablesWebContext.CreateContext())
                {
                    var user = db.Users.SingleOrDefault(x => x.Guid == reset.UserGuid);

                    if (user != null)
                    {
                        String newPass = GenerateRandomPassword();
                        user.Password = Tango.BL.Entities.User.GetPasswordHash(newPass);
                        user.PasswordChangeRequired = true;
                        vm.Password = newPass;
                        vm.FullName = reset.FullName;
                        db.SaveChanges();
                    }
                }
            }

            return View(vm);
        }

        private String GenerateRandomPassword()
        {
            String pass = String.Empty;

            for (int i = 0; i < 4; i++)
            {
                pass += rnd.Next(0, 9).ToString();
            }

            return pass;
        }
    }
}